package util

import (
	"fmt"
	"strings"
	"time"
)

const contParse = "2006-01-02 15:04:05"

func GetStrTimeNow() string {
	currentTime := time.Now()
	// contParse := "2006-01-02 15:04:05"
	formattedTime := currentTime.Format(contParse)
	return formattedTime
}

func Ff(fstr time.Time) string {
	return fstr.Format(contParse)
}

// 解析形如 "key:value|key:value" 的字符串，并转换为 map

func ParseStringToMap(input string) (map[string]string, error) {
	result := make(map[string]string)
	pairs := strings.Split(input, "|")
	for _, pair := range pairs {
		splitPair := strings.Split(pair, ":")
		if len(splitPair) != 2 {
			return nil, fmt.Errorf("invalid input format: %s", pair)
		}
		key := strings.TrimSpace(splitPair[1])
		value := strings.TrimSpace(splitPair[0])
		result[key] = value
	}
	return result, nil
}
